package cn.yj.wx.pay.service.handler;

import cn.yj.common.emums.PayFrom;
import cn.yj.common.exception.PayException;
import cn.yj.commons.utils.StringUtils;
import cn.yj.wx.pay.enrity.PayOrderResult;
import cn.yj.wx.pay.enrity.WechatPayRequest;

import java.util.Map;

/**
 * @author 永健
 * @since 2021-09-22 16:32
 */
public class H5Pay extends AbstractWxPay<PayOrderResult, WechatPayRequest> {

    private static final String PAY_URL = "https://api.mch.weixin.qq.com/v3/pay/transactions/h5";

    @Override
    protected void checkPayRequestParams(WechatPayRequest wechatPayRequest) {
        Map<String, Object> params = wechatPayRequest.getScene_info();
        if (StringUtils.isNull(params)) {
            throw new PayException("缺少支付场景描述scene_info");
        }
    }

    @Override
    public PayOrderResult underOrder(WechatPayRequest wechatPayRequest) throws PayException {
        return super.doUnderOrder(PAY_URL, wechatPayRequest);
    }

    @Override
    public boolean support(PayFrom payFrom) {
        return payFrom == PayFrom.H5;
    }
}
